import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import '../../helper/channelHelper.dart';

import '../../helper/routeHelper.dart';
import '../../helper/uidata.dart';
import '../../model/danger2.dart';

import '../../widgets/inputWidget.dart';
import '../../widgets/signatureCard2.dart';

import '../../helper/Helper.dart';

class Danger2DealPage extends StatefulWidget {
  Danger2DealPage(this.cb1, this.added);
  final Danger2 cb1;
  final VoidCallback added;

  @override
  Danger2DealPageState createState() => new Danger2DealPageState();
}

class Danger2DealPageState extends State<Danger2DealPage> {
  final String now = Helper.DateTimeNowString();
  final TextEditingController c1 = new TextEditingController();
  bool ifLoad = true;
  late Danger2 s1;

  @override
  void initState() {
    super.initState();
    s1 = widget.cb1;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      //backgroundColor: Colors.white,
      appBar: AppBar(
        title: Text("整改完成情况验收"),
      ),
      // floatingActionButton: InputWidget.getQMButton(context, "整改验收签字",signIt1 ),
      body: ifLoad
          ? CleanInfoBody(context)
          : Center(
              child: SpinKitCircle(
              color: Colors.blue,
            )),
    );
  }

  CleanInfoBody(BuildContext context) => SingleChildScrollView(
        child: CleanInfoFields(context),
      );

  signIt1(String imgId) async {
    s1.State = 2;
    s1.CheckQMTM = Helper.DateTimeNowString();
    s1.CheckQM = imgId;
    s1.DealResult = c1.text;
    await Danger2.Update(s1);
    widget.added();
    Navigator.of(context).pop();
    // await Danger2.Update(s1);
    // loadData();
    //await Helper.sendMessage("审核通知", "18884230190");
  }

  List<Widget> getWidgetList(BuildContext context) {
    List<Widget> list1 = <Widget>[];
    List<Widget> list3 = <Widget>[];
    List<Widget> list4 = <Widget>[];
    List<Widget> list2 = <Widget>[];
    List<Widget> list5 = <Widget>[];

    // list3.add(InputWidget.getInfo("标题", s1.Title));
    // list3.add(InputWidget.getDivider());
    // list3.add(InputWidget.getInfo2("内容简述", s1.Content));
    // list3.add(InputWidget.getDivider());
    // list3.add(InputWidget.getInfo("登记时间",Helper.DateTimeFormat(s1.CreateTM)));

    list4.add(InputWidget.getInput2("整改完成情况", c1));
    //list4.add(InputWidget.getQMTile2("验收确认签字", s1.State>=3, s1.CheckQM, s1.CheckQMTM)   );
    //list1.add(InputWidget.inCard2(list3));S
    list1.add(InputWidget.inCard2(list4));

    list1.add(InputWidget.inCard(InputWidget.getButton("签字确认", () {
      showPanel(context, signIt1, "整改验收签字");
    })));
    //list1.add(getCLWidget(s1.State==6, Helper.DateTimeFormat(s1.HZQMTM), s1.HZQM));

    return list1;
  }

  void showPanel(
      BuildContext context, SignaturedCallback checkIt, String title) {
    showModalBottomSheet(
      context: context,
      builder: (BuildContext context) {
        return SignatureCard2Page(checkIt, title);
      },
    );
  }

  upload(BuildContext context) async {
    if (s1.State < 2) {
      ChannelHelper.showToast("请先完成验收签字再提交!");
      return;
    }
    s1.DealResult = c1.text;
    await Danger2.Update(s1);
    widget.added();
    Navigator.of(context).pop();
  }

  CleanInfoFields(BuildContext context) => Container(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.end,
          children: getWidgetList(context),
        ),
      );
}
